package com.googlecode.FWT.model
{
	import com.googlecode.FWT.data.ProjectDataVO;
	
	import org.puremvc.as3.patterns.proxy.Proxy;

	public class ProjectDataProxy extends Proxy
	{
		/**
		 * PureMVC identifier 
		 */		
		public static const NAME:String = "ProjectDataProxy";
		
		public static const PAGE_INDEX_CHANGED:String = "Page.Index.Changed";
		
		public static const NUMBER_PAGES_CHANGED:String = "Number.Pages.Changed";
		
		/**
		 * Constructor 
		 * 
		 */
		public function ProjectDataProxy()
		{
			super(NAME, new ProjectDataVO());
		}
		
		/**
		 * Stores the index of the loaded page. This number cannot be below zero or above the number of pages -1.
		 * @param index
		 * 
		 */	 
		public function set loadedPageIndex(index:int):void
		{
			
			// only numbers >= 0 are acceptable
			
			// ignore first page going backwards
			if(loadedPageIndex == 0 && index < 0)
			{
				return
			}
			// only numbers one below the total number of pages are acceptable
			if(index > numPages)
			{
				return;
			}
			// set loaded page index
			settings.loadedPageIndex = index;

			// send notification that page has changed
			sendNotification(PAGE_INDEX_CHANGED, index);
		}
		
		/**
		 * Returns the loaded page index. 
		 * @return 
		 * 
		 */ 
		public function get loadedPageIndex():int
		{
			return settings.loadedPageIndex;
		}
		
		/**
		 *  
		 * @param pages Contains int.
		 * 
		 */
		public function set numPages(pages:int):void
		{
			settings.numPages = pages;
			sendNotification(NUMBER_PAGES_CHANGED, pages);
		}
		
		/**
		 * Returns number of pages in project. 
		 * @return 
		 * 
		 */
		public function get numPages():int
		{
			return settings.numPages;
		}
		
		/**
		 * Stores the name of the user. 
		 * @param name
		 * 
		 */
		public function set userName(text:String):void
		{
			settings.name = text;
		}
		
		/**
		 * Returns the name of the user.
		 * @return 
		 * 
		 */
		public function get userName():String
		{
			return settings.name as String;					
		}
			
		/**
		 * Stores the essay title. 
		 * @param name
		 * 
		 */
		public function set essayTitle(text:String):void
		{
			
			settings.essayTitle = text;
		}
		
		/**
		 * Returns the essay  title.
		 * @return 
		 * 
		 */	 
		public function get essayTitle():String
		{
			return settings.essayTitle as String;
			
		}
		
		/**
		 * Typed reference to the data stored in the proxy. 
		 * @return
		 */	
		public function get settings():ProjectDataVO
		{
			return getData() as ProjectDataVO;
		}
	}
}